from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium import webdriver

driver = webdriver.Edge()
driver.maximize_window()
driver.get('https://www.jiuxian.com/')
sleep(2)
# 点击请登录
dl = driver.find_element(By.CLASS_NAME,'headerLogin')
dl.click()
sleep(1)
# # 点击qq登录
# driver.find_element(By.XPATH,'//*[@id="loginform"]/div/div/div/div/div[1]/div[4]/div/a[1]/i').click()
# sleep(1)
# f = driver.find_element(By.ID,'ptlogin_iframe')
# driver.switch_to.frame(f)
# # 点击qq授权
# driver.find_element(By.ID,'img_out_3047217905').click()
# 输入账号
driver.find_element(By.ID,"userName").send_keys('18185603008')
sleep(2)
# 输入密码
driver.find_element(By.ID,'password').send_keys('123456Aa')
sleep(10)
#点击登录
dl = driver.find_element(By.NAME,'bi_Usuallogin')
sleep(2)
# 点击确定
driver.find_element(By.ID,'bindSub').click()
sleep(2)
# 断言
dy1 = driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span').text
assert dy1 == 'jxw824726828'
print(dy1)
sleep(2)
search = driver.find_element(By.ID,'wd')
search.send_keys('国台')
sleep(2)
search.send_keys(Keys.ENTER)
sleep(2)
driver.find_element(By.XPATH,'//a[@href=" http://shop.jiuxian.com/brand-20.htm "]').click()
sleep(2)
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
#向下滚动2000像素
driver.execute_script("window.scrollTo(0,2000)")
sleep(2)
driver.find_element(By.XPATH,'//*[@id="layoutContain"]/div/div/div/div/div/map[1]/area').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
# 断言2 53°国台品鉴  500ml
dy2 = driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/h1').text
print(dy2)
# assert dy2 == '53°国台品鉴  500ml'
sleep(2)
# 点击到货通知
driver.find_element(By.ID,'addToCartForDetail').click()
sleep(2)
driver.find_element(By.CLASS_NAME,'notify-form').send_keys(Keys.CONTROL,'a')
sleep(2)
# driver.find_element(By.CLASS_NAME,'notify-form').send_keys(Keys.CONTROL,'x')
# sleep(2)
# delete键
# driver.find_element(By.CLASS_NAME,'notify-form').send_keys(Keys.DELETE)
# sleep(2)
driver.find_element(By.CLASS_NAME,'notify-form').send_keys(Keys.BACK_SPACE)
sleep(2)
driver.find_element(By.CLASS_NAME,'notify-form').send_keys('3047217905@qq.com')
sleep(2)



sleep(5)



